package huizhi.net;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 *
 2、客户端上传一个花桶编号，服务端响应花桶中的花卉代码
 */
public class ClientDatabase1 {
    public static void main(String[] args) throws Exception {
//        // 连接本机的8888端口
//        Socket client = new Socket(InetAddress.getLocalHost(), 8888);
//        // 从套接字获取字节输出流
//        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
//        bufferedWriter.write("hello, Server！");
//        bufferedWriter.newLine();
//        bufferedWriter.flush();
//
//
//        // 获取客户端输入字节流
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
//        String respMsg = bufferedReader.readLine();
//        System.out.println(respMsg);
        // 连接本机的8888端口
        System.out.println("客户端启动");
        System.out.println("客户端向服务端传入HT20231016");
        Socket client = new Socket(InetAddress.getLocalHost(), 8880);
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
        bufferedWriter.write("HT20231016");
        bufferedWriter.newLine();
        bufferedWriter.flush();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
        String respMsg = bufferedReader.readLine();
        System.out.println("-------------------");
        System.out.println("服务端向客户端传入：");
        System.out.println(respMsg);
        bufferedWriter.close();
        bufferedReader.close();
        client.close();
    }
}
